package com.jiayan.service;

import com.jiayan.mapper.EbProductCategoryMapper;
import com.jiayan.mapper.EbProductMapper;
import com.jiayan.model.EbProduct;
import com.jiayan.model.EbProductCategory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@Service
public class GoodsService {
    @Resource
    private EbProductMapper ebProductMapper;
    @Resource
    private EbProductCategoryMapper ebProductCategoryMapper;

    /**
     *根据商品 id查询商品的详情 信息
     * @param pid  商品id
     * @return
     */
    public EbProduct detail(Integer pid){
        EbProduct goods = ebProductMapper.selectById(pid);
        System.out.println("商品"+goods);

        return goods;
    }

    public Map<String, EbProductCategory> linkedCateByProduct(Integer pid){
        Map<String,EbProductCategory> result=new HashMap<>(2);
        EbProduct ebProduct=ebProductMapper.selectById(pid);
        EbProductCategory bigCate= ebProductCategoryMapper.selectById(ebProduct.getEpcId());
        EbProductCategory smallCate= ebProductCategoryMapper.selectById(ebProduct.getEpcChildId());

        result.put("big",bigCate);
        result.put("small",smallCate);
        return result;
    }
}
